const router = require('koa-router')()
const User = require('../models/User')
const Class = require('../models/Class')
const { roleType } = require('../common/type')
const Teacher = require('../models/Teacher')



router.get('/test', async (ctx, next) => {
  // const res = await Student.getStudentsInfo({})
  // ctx.body = res
  // console.log(res);
  // const res = await Teacher.getTeachersInfo()
  // const res = await User.findUsersByRoleType(roleType.ADMIN)
  // ctx.body = res
  // const res = await Class.createClass('三色班');
  // const res = await User.createStudent({ username: 'Lionel5', password: '123', name: 'yzs', grade: '2019', school: '财大', ClassId: 'c5c42cd2-1a5e-4731-952b-19fd6e9520ad' })
  // const res = await User.findUserByUsername('Lionel')
  // await User.createTeacher({ username: 'wn2', password: '123', name: 'wn', tel: '123' })
  // ctx.body = res
  // console.log(res);

  ctx.body = {
    code: 200,
    message: "success"
  }
});

router.post('/login', async (ctx, next) => {
  const { username, password } = ctx.request.body
  const user = await User.findUserByUsername(username)
  if (!user) {

  }
})

router.get('/checkUsername', async (ctx, next) => {
  const { username } = ctx.request.query
  console.log(username);
  const  res  = await User.findUserByUsername(username)
  if (res) {
    ctx.body = {
      code: 200,
      hasUser: true,
      message: "success"
    }
  } else {
    ctx.body = {
      code: 200,
      hasUser: false,
      message: "success"
    }
  }
})


module.exports = router
